package as2.model;

import org.hibernate.Session;
import org.junit.Test;

import as2.model.pojo.User;
import as2.model.security.BCrypt;

public class UserService extends DataService {
	public static User getUser(String user_id, String password) {
		Session session = getSession();
		session.beginTransaction();
		User user = (User) session.get(User.class, user_id);
		session.getTransaction().commit();

		if (user != null) {
			String expectedHashedPw = user.getPassword();
			// BCrypt.hashpw(password, BCrypt.gensalt());

			// pw doesnt match
			if (!BCrypt.checkpw(password, expectedHashedPw)) {
				return null;
			}
		}
		return user;
	}

	@Test
	public void test() {
		User user = getUser("user1", "user1pw");
		System.out.println(user);
	}
}
